<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.14/vue.js"></script>
</head>
<body>
    <div id="app">
        <tom></tom> 
        <jerry></jerry>
    </div>
</body>
<script>
//定义事件总线
//两个组件,通过事件总线来收发消息
let eventBus = new Vue({})    
Vue.component('Tom', {
    template: `
        <div>Tom组件<button @click="handleAdd">+1</button></div>
    `,
    methods: {
        handleAdd(){
            eventBus.$emit('add')

        }
    }
})   
Vue.component('Jerry', {
    template: `
        <div>Jerry组件-{{count}}</div>
    `,
    data(){
        return {
            count: 0
        }
    },
    mounted(){
        eventBus.$on('add',()=>{
            this.count++
        })
    }
})    
let vm = new Vue({
    el: '#app',
    data(){
        return {
           
        }
    }
})
</script>
</html>